<?php
/**
 * 分页处理类
 * @author kwor
 *
 */
if (!defined('VALIDADMIN')) die ('Access Denied.');

class cls_thems{

	/**
	 *
	 * @param string $fileName
	 * @param string $method
	 */
	function readover($fileName, $method = 'rb') {
		$fileName = Pcv($fileName);
		$data = '';
		if ($handle = @fopen($fileName, $method)) {
			flock($handle, LOCK_SH);
			$data = @fread($handle, filesize($fileName));
			fclose($handle);
		}
		return $data;
	}


	function get_them_dir($dir='.')
	{
		header("Content-Type:text/html;charset=utf-8");

		$infodb = array();
		$thempath = opendir($dir);
		while (($them_dir = readdir($thempath))) {
			if (strpos($them_dir,'.')===false && file_exists("templates/$them_dir/info.xml")) {
				if (function_exists('file_get_contents')) {
					$filedata = @file_get_contents("templates/$them_dir/info.xml");
				} else {
					$filedata = $this->readover("templates/$them_dir/info.xml");
				}
				if (preg_match('/\<title\>(.+?)\<\/title\>\s+\<author\>(.+?)\<\/author\>\s+\<url\>(.+?)\<\/url\>\s+\<desc\>(.+?)\<\/desc\>\s+\<defaultimg\>(.+?)\<\/defaultimg\>/is',$filedata,$infodb)) {
					$title=$infodb[1];
					$url = $infodb[3];
					$author = "<a href='".$url."'>".$infodb[2]."</a>";
					$desc = $infodb[4];
					$defaultimg = $infodb[5];
				}
				if($title!=""&&$author!=""&&$url!=""&&$desc!=""&&$defaultimg!=""&&$title!=null&&$author!=null&&$url!=null&&$desc!=null&&$defaultimg!=null){
						$uninstalldb[] = array(title=>$title,author=>$author,dir=>$them_dir,desc=>$desc,defaultimg=>$defaultimg);		
				}
			}
		}
		closedir($thempath);
		return $uninstalldb;
	}
}
?>